export default {
	data () {
            return {
                baseData: [],
                formValidate:{
                	title:'',
                	type:1,
                	parentId:null
                	
                },
                data2:[],
                data3:[],
                queryParams:{},
                onoff:false,
                filter:{
					page: 1,
					limit: 2,//一页显示2条
					name:'',
					total:0
				}
            }
        },
        created(){
        	this.getTree(1)
        },
        methods:{
        	changedata(){
        		if(this.onoff){
        			if(this.formValidate.parentId){
        				this.data2.forEach((ids)=>{
	        				this.$http({//修改子节点
								method:'post',
								url:`http://localhost:3000/${this.module2}/data/`+ids._id,
								data:this.formValidate
							})
							.then(res=>{
								this.getTree(this.formValidate.type);
								this.formValidate.title="";
								this.data2 = [];
							})
						})	
        			}else{
	        			this.data2.forEach((ids)=>{//修改根节点
							this.$http({
			    				method:'post',
			    				url:`http://localhost:3000/${this.module2}/data/`+ids._id,
								data:this.formValidate
			    			}).then((response)=>{
			        			this.getTree(this.formValidate.type)
			        			this.formValidate.title=""
			        			this.data2 = [];
			        		})
						})
	        		}
        			
        		}else{
        			
        			if(this.formValidate.parentId){
        				console.log(this.formValidate)
        				this.$http({//增加子节点
							method:'post',
							url:`http://localhost:3000/${this.module2}/data/`,
							data:this.formValidate
						})
						.then(res=>{
							this.getTree(this.formValidate.type)
							this.formValidate.title=""
			
						})
		        	}else{
		        		this.$http({//增加根节点
							method:'post',
							url:`http://localhost:3000/${this.module2}/data/`,
							data:this.formValidate
						})
						.then(res=>{
							this.getTree(this.formValidate.type)
							this.formValidate.title=""
			
						})
		        	}      		
        		}
        		
        	},
        	changeType(type){
        		this.formValidate.type = type;
        		this.getTree(type)
        	},
        	getTree(type){
        		this.$http({
	        		url:`http://localhost:3000/${this.module2}/list/`+ type,
	        		method:'get'
	        	}).then(res=>{
	        		this.baseData = res.data
	        	})
        	},
        	deleted(){      		
        		this.data2.forEach((ids)=>{
        			console.log(ids._id)
					this.$http({
	    				method:'delete',
	    				url:`http://localhost:3000/${this.module2}/data/`+ids._id,
	
	    			}).then((response)=>{
	        			this.getTree(this.formValidate.type)
	        			this.formValidate.title=""
	        			this.data2 = [];
	        		
	        		})
				})
        	},
        	amend(){
        		this.data2.forEach((ids)=>{
        			
        			this.formValidate.title=ids.title
					this.onoff = true
				})
        	},
        	addition(arrs){ //点击根节点
        		this.data2=arrs;

        	},
        	additionson(){ //点击增加子节点
        		this.data2.forEach((ides)=>{
        			this.formValidate.parentId=ides._id;
0
        		})
        		
        	},
        	getCataid(arrs){
        		this.data3=arrs;
        		this.data3.forEach((ids)=>{
        			var id = ids._id
					this.init(id)
        		})
        	},
        	init(cateId){
        		
        		this.$http({
	        		url:'http://localhost:3000/news/list',
	        		method:'post',
	        		data:{
	        			cateId:cateId
	        		}
	        	}).then(res=>{	        		
					this.list = res.data.rows;
					this.filter.total = res.data.total;
	        	}) 
        	},
        	
	        	
        }
}
